#include "MyInputMgr.h"
extern HWND g_hWnd;
extern int g_iWndWidth;
extern int g_iWndHeight;
extern int g_iWidth;
extern int g_iHeight;

CMyInputMgr::CMyInputMgr(void)
{
	m_kMousePt.x = m_kMousePt.y = 0;
	m_hImc = NULL;
}

CMyInputMgr::~CMyInputMgr(void)
{
}

bool CMyInputMgr::IsLeftBtnDown()
{
	return (GetAsyncKeyState(VK_LBUTTON) & 0x8000) > 0;
}

bool CMyInputMgr::IsRightBtnDown()
{
	return (GetAsyncKeyState(VK_RBUTTON) & 0x8000) > 0;
}

bool CMyInputMgr::IsMidBtnDown()
{
	return (GetAsyncKeyState(VK_MBUTTON) & 0x8000) > 0;
}

bool CMyInputMgr::IsKeyDown( BYTE byKey )
{
	return (GetAsyncKeyState(byKey) & 0x8000) > 0;
}

int CMyInputMgr::GetMouseX()
{
	return (int)(m_kMousePt.x * ((float)g_iWidth / (float)g_iWndWidth));
}

int CMyInputMgr::GetMouseY()
{
	return (int)(m_kMousePt.y * ((float)g_iHeight / (float)g_iWndHeight));
}

void CMyInputMgr::Update()
{
	GetCursorPos(&m_kMousePt);
	ScreenToClient(g_hWnd,&m_kMousePt);
	return;
}

void CMyInputMgr::CloseIME()
{
	if (m_hImc)
	{
		ImmSetOpenStatus(m_hImc,FALSE);
	}
	else
	{
		m_hImc = ImmGetContext(g_hWnd);
		ImmSetOpenStatus(m_hImc,FALSE);
		ImmReleaseContext(g_hWnd,m_hImc);
	}
}

void CMyInputMgr::OpenIME()
{
	if (m_hImc)
	{
		ImmSetOpenStatus(m_hImc,TRUE);
	}
	else
	{
		m_hImc = ImmGetContext(g_hWnd);
		ImmSetOpenStatus(m_hImc,TRUE);
		ImmReleaseContext(g_hWnd,m_hImc);
	}
}

void CMyInputMgr::EnableIME()
{
	if (m_hImc)
	{
		ImmAssociateContext(g_hWnd,m_hImc);
	}
}

void CMyInputMgr::DisableIME()
{
	m_hImc = ImmAssociateContext(g_hWnd,NULL);
}

bool CMyInputMgr::IsShiftDown()
{
	return IsKeyDown(VK_SHIFT);
}

bool CMyInputMgr::IsCtrlDown()
{
	return IsKeyDown(VK_CONTROL);
}

bool CMyInputMgr::IsAltDown()
{
	return IsKeyDown(VK_MENU);
}
